package com.dymall.cart.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dymall.cart.domain.dto.CartItemDTO;
import com.dymall.cart.domain.pojo.CartItem;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface CartItemMapper extends BaseMapper<CartItemMapper> {
    @Select("select * from cart_item where cart_id = #{cardId}")
    List<CartItem> selectByCartId(Long cartId);

    @Select("select * from cart_item where cart_id = #{cartId} and product_id = #{productId}")
    CartItem findItem(Long cartId, Long productId);

    @Insert("insert into cart_item (cart_id, product_id, quantity) values (#{cartId},#{productId},#{quantity})")
    void insertItem(CartItem item);

    @Update("update cart_item set quantity = #{quantity} where cart_id = #{cartId} and product_id = #{productId}")
    void incQuantity(Long cartId, Long productId, Integer quantity);

    // 清空购物车
    @Delete("delete from cart_item where cart_id = #{cartId}")
    void clearCart(Long cartId);

    // 删除一条
    @Delete("delete from cart_item where cart_id = #{cartId} and product_id = #{productId}")
    Long deleteItemById(@Param("cartId") Long cartId, @Param("productId") Long productId);

    // 根据购物车 ID 和多个商品 ID 批量删除商品
    Long deleteItems(@Param("cartId") Long cartId, @Param("productIds") List<Long> productIds);
}
